package com.example.azheng.okhttpdemo.utils;

import com.example.azheng.okhttpdemo.beans.JuheBean;
import com.example.azheng.okhttpdemo.retrofit.RetrofitClient;


import io.reactivex.Observable;

import io.rx_cache2.DynamicKey;
import io.rx_cache2.EvictDynamicKey;

/**
 * @author azheng
 * @date 2018/4/18.
 * GitHub：https://github.com/RookieExaminer
 * email：wei.azheng@foxmail.com
 * description：
 */
public class Repository {
    private static volatile Repository instance;

    public Repository() {
    }

    public static Repository getInstance() {
        if (instance == null) {
            synchronized (Repository.class) {
                if (instance == null) {
                    instance = new Repository();
                }
            }
        }
        return instance;

    }

    //参数update：是否加载最新数据
    public Observable<JuheBean> getData(boolean update) {
        return CacheProviders.getInstance().getData(RetrofitClient.getInstance().getApi().getData(),new DynamicKey("JuheBeans"), new EvictDynamicKey(update));
    }

}
